package com.chengyu.core.controller.shop;

import com.chengyu.core.component.OperationLog;
import com.chengyu.core.controller.UserBaseController;
import com.chengyu.core.domain.CommonConstant;
import com.chengyu.core.domain.result.ShopCateResult;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.UmsShopCate;
import com.chengyu.core.service.shop.ShopCateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "店铺分类")
@Controller
@RequestMapping("/common")
public class ShopCateListController extends UserBaseController {

//	private Integer status;
//	private Integer type;

	@Autowired
	private ShopCateService shopCateService;

//	@ApiOperation(value = "店铺类目列表")
//	@ResponseBody
//	@RequestMapping(value="/shopCat/getList", method=RequestMethod.GET)
//	public CommonResult<List<ShopCateResult>> getList(Integer status, @RequestParam(value = "type", defaultValue = "1") Integer type) throws ServiceException {
////		this.status = status;
////		this.type = type;
//		if (type == null || type.equals(0)){
//			type = 1;
//		}
////		List<ShopCateResult> list  = shopCateService.getShopCateResults(getCurrentShop().getId(), status,type);
//		List<ShopCateResult> list  = shopCateService.getShopCateResults(getCurrentShop().getId(), status);
//		return CommonResult.success(list);
//	}


	@ApiOperation(value = "店铺分类列表")
	@ResponseBody
	@RequestMapping(value="/shopCate/getList", method=RequestMethod.GET)
	public CommonResult<List<ShopCateResult>> getList(Integer shopId) throws ServiceException {

		if (shopId == null || shopId.equals(0)){
			if(getCurrentShop()!=null){
				shopId = getCurrentShop().getId();
			}else{
				List<ShopCateResult> list = new ArrayList<>();
				return CommonResult.success(list);
			}

		}

		List<ShopCateResult> list = shopCateService.getShopCateResults(shopId, CommonConstant.YES_INT);

		return CommonResult.success(list);
	}




	@ApiOperation(value = "店铺服务类目列表")
	@ResponseBody
	@RequestMapping(value="/getServiceList", method=RequestMethod.GET)
	public CommonResult<List<ShopCateResult>> getListService(Integer status) throws ServiceException {
		List<ShopCateResult> list = shopCateService.getShopCateServiceResults(getCurrentShop().getId(), status);
		return CommonResult.success(list);
	}

}
